<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!doctype html>
<html>
	<head>
		<base href="<%=basePath%>" />
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<meta name="apple-mobile-web-app-title" content="Amaze UI" />
		<link rel="stylesheet" href="layui/css/layui.css" media="all"> <!-- 适应所有设备 -->
		<style type="text/css">
		</style>
	</head>
	<% String nowDay = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); %>
	<body>
	
	    <form class="layui-form" onsubmit='return false'>
	      <br/>
	    <table class="layui-table" id="LAndN" lay-filter="LAndN">
	    </table>
	      <br/>
		<div class="layui-form-item">
			<div class="layui-input-inline">
				<input type="text" name="playerID" id="playerID" placeholder="搜寻二级ID"
					autocomplete="off" class="layui-input">
			</div>

			<div class="layui-inline">
				<div class="layui-input-inline">
					<button class="layui-btn layui-btn-normal" data-type="reload"
						id="SelectOrder" lay-filter="SelectOrder">搜索</button>
				</div>
			</div>
		</div>
		<table class="layui-table" id="Agent" lay-filter="Agent">
		<caption style="color:#d71345">一级代理信息</caption>
		</table>
		<br/>
		
		
	    </form>
	    
	    <script src="js/jquery.min.js"></script>
		<script src="layui/layui.js"></script>
		<script>
		    layui.use(['layer','form','table'],function(){
		    	var layer = layui.layer,
		    	    form  = layui.form,
		    	    table = layui.table;
		    	
		    	layer.config({
					extend: 'MySkin/style.css'
				});
		    	
		    	var data;
	          	$(document).ready(function(){
	          		$.ajax({
	          			type:"POST",
	          			url:'agent/CountStat',
	          			async:false,
	          			success:function(resp){
	          				data=JSON.parse(resp);
	          			}
	          		});
	          	});
		    	
		    	table.render({
		    		elem:'#LAndN',
		    		method:'post',
		    		title:'代理等级和信息',
		    		skin: 'row',
		    		even: true,
		    		page : false,//分页
		    		autoSort: false,
		    		id:'AllTable2',
		    		request:{
						pageName:'PageIndex',
						limitName:'PageCount'
					},
		    		cols:[[
		    			{field:'Level',title:'代理等级',style:'color:#d71345'},
		    			{field:'Number',title:'代理数量 ',style:'color:#f47920'},
		    			]],
						response : {
							statusCode : 200
						//重新规定成功的状态码为 200，table 组件默认为 0
						},
						data:data.data
		    	});
		    	
		    	
		    	table.render({
		    		elem:'#Agent',
		    		method:'post',
		    		title:'一级代理信息',
		    		url:'agent/List',
		    		skin: 'row',
		    		even: true,
		    		page : true,//分页
		    		autoSort: false,
		    		id:'AllTable',
		    		request:{
						pageName:'PageIndex',
						limitName:'PageCount'
					},
					where:{
						UserId : $('#playerID').val()
					},
		    		cols:[[
		    			{field:'UserId',title:'ID',style:'color:#d71345'},
		    			{field:'Nickname',title:'昵称',style:'color:#f47920'},
		    			{field:'SubUserCount',title:'旗下2级代理数量',style:'color:#f05b72'},
		    			{field:'Assets',title:'当前总贡献',style:'color:#1d953f'},
		    			{field:'TotalAssets',title:'旗下代理总贡献',style:'color:#009ad6'},
		    			{field:'TotalWarheadCount',title:'总兑换弹头',style:'color:#5c7a29'}
		    			]],
		    			response:{
							statusCode : 200
						},
						parseData:function(res){
							return{
								"code":res.status,
								"msg":res.message,
								"count":res.count,
								"data":res.data
							};
						}
		    	});
		    	
		    	
		    	
		    	
		    	//定时刷新数据
				setInterval(function(){
					table.reload('AllTable', {});
					var data;
					$.ajax({
	          			type:"POST",
	          			url:'agent/CountStat',
	          			async:false,
	          			success:function(resp){
	          				data=JSON.parse(resp);
	          			}
	          		});
					table.reload('AllTable3', {});
	              },60000);
		    	
				
				//根据条件查询表格数据重新加载
				var active = {
					reload: function() {
						//获取用户名
						//执行重载
						table.reload('AllTable', {
							page: {
								curr: 1 //重新从第 1 页开始
							}
							//根据条件查询
							,
							where: {
								UserId : $('#playerID').val()
							}
						});
						return false;
					}
				};
				//点击搜索按钮根据用户名称查询
				$('#SelectOrder').on('click',
					function() {
						var type = $(this).data('type');
						active[type] ? active[type].call(this) : '';
					});
				
				
				var active2 = {
						reload: function() {
							//获取用户名
							//执行重载
							table.reload('AllTable3', {
								page: {
									curr: 1 //重新从第 1 页开始
								}
								//根据条件查询
								,
								where: {
									UserId : $('#playerID2').val()
								}
							});
							return false;
						}
					};
				
				//点击搜索按钮根据用户名称查询
				$('#SelectOrder2').on('click',
					function() {
						var type = $(this).data('type');
						active2[type] ? active2[type].call(this) : '';
					});
		    	
		    });
		</script>
    </body>
</html>